<template>
  <div class="demo">
    <div class="login">
      <div class="title">注册</div>
      <el-form :rules="rules" :model="Login_Form" ref="ruleFormRef">

      

      
        <el-form-item prop="username">
          <el-input v-model="Login_Form.username" clearable type="string" size="large" placeholder="请输入你的账号">
          </el-input>
        </el-form-item>


        <el-form-item prop="PassWord">
          <el-input v-model="Login_Form.PassWord" clearable show-password type="string" class="Input_Username"
            size="large" placeholder="请输入你的密码">
          </el-input>
        </el-form-item>

        <el-form-item prop="name">
          <el-input v-model="Login_Form.name" clearable type="string" size="large" placeholder="请输入你的昵称">
          </el-input>
        </el-form-item>

        <el-form-item prop="mobilePhone">
          <el-input v-model="Login_Form.mobilePhone" clearable type="string" size="large" placeholder="请输入你的手机号">
          </el-input>
        </el-form-item>

        <el-form-item prop="Personal">
          <el-input v-model="Login_Form.Personal" clearable  type="string" class="Input_Username"
            size="large" placeholder="请输入你的个性签名">
          </el-input>
        </el-form-item>
        <el-form-item prop="school">
          <el-input v-model="Login_Form.school" clearable type="string" class="Input_Username" size="large"
            placeholder="请输入你的学校">
          </el-input>
        </el-form-item>


      </el-form>
      <div class="button">
        <el-button @click="submitForm(ruleFormRef)" style="height: 50px; width: 100%;">立即注册</el-button>
      </div>
      <div class="Register" @click="Register">返回</div>


    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { rules } from '../../utils/Method/Check.js' //引入校验规则
import {Registers} from '../../ApI/function/Login.js'
const Router = useRouter()


const Login_Form = reactive({
  name: null,
  mobilePhone: null,  // 用户输入用户名
  PassWord: null,  // 用户输入密码
  agreement: null,
  mobilePhone: null,
  Personal: null,
  school: null,
  username:null
})

/* 登录之表单校验 */
const ruleFormRef = ref()
const submitForm = (formEl) => {
  if (!formEl) return
  formEl.validate((valid, firlds) => {
    if (valid) {
      Registeraxios()
    } else {
    }
  })
}
// 跳转至注册
const Register = () => {
  Router.push('/login')
}

const Registeraxios = () => {
  Registers({
    phone: Login_Form.mobilePhone,
    username:Login_Form.username,
    password: Login_Form.PassWord,
    nick:Login_Form.name,
    sign:Login_Form.Personal,
    school:Login_Form.school,
  }).then(res => {
    console.log(res)
    if(res.code == "0000"){
      ElMessage({
        message: '恭喜你注册成功',
        type: 'success',
      })
      Router.push('/login')
    }else{
      ElMessage.error(res.msg)
    }

  })

}

</script>

<style lang="less" scoped>
.demo {
  display: flex;
  height: 100vh;
  background-color: #F5F6F8;
  background-image: url(https://ycc888.oss-cn-hangzhou.aliyuncs.com/%E7%8C%BF%E6%9F%A5%E6%9F%A5%E5%9B%BE%E7%89%87/login.png);


  .login {
    width: 500px;
    padding: 10px 0px;
    border-radius: 20px;
    background-color: #fff;
    margin: auto;
    padding: 50px;
    box-sizing: border-box;
    cursor: pointer;


    .el-input {
      height: 45px;
      margin-bottom: 5px;
    }

    .title {
      margin-bottom: 20px;
      font-size: 26px;
    }

    .Register {
      color: #409EFF;
      font-size: 14px;
      margin-top: 10px;
    }
  }
}
</style>